package com.hunter.studentsystem.Student.controller;

import com.hunter.studentsystem.Student.Student;
import com.hunter.studentsystem.Student.service.StudentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/api/vi/student")
public class StudentController {
    @Resource
    private StudentService studentService;

    /**
     * 获取学生信息
     *
     * @return
     */
    @GetMapping
    public List<Student> getStudent() {
        return studentService.getStudents();
    }


    /**
     * 保存学生信息
     *
     * @param student
     */
    @PostMapping
    public void saveStudent(@RequestBody Student student) {
        studentService.saveStudent(student);
    }

    /**
     * 删除学生信息
     *
     * @param studentId
     */
    @DeleteMapping(path = "{studentId}")
    public void deleteStudent(@PathVariable Long studentId) {
        studentService.deleteStudentById(studentId);  // 只传递 studentId
    }


    /**
     * 更新学生信息
     *
     * @param studentId
     * @param name
     * @param email
     */
    @PutMapping(path = "{studentId}")
    public void updateStudentById(@PathVariable Long studentId,
                                  @RequestParam String name,
                                  @RequestParam String email) {
        studentService.updateStudentById(studentId, name, email);
    }
}
